<template>
	<view class="container">
		<uni-swipe-action v-if="recordingData.length" threshold='1'>
		<uni-swipe-action-item  v-for="(item,index) in recordingData" class="action-item" :right-options="options" @tap="onClickss($event,item)">
		<uni-list border-full  @click="nursingDetail(item)" >
			<uni-list-item :title="item.xm||'--'" :note="'所属组:'+item.deptname||'--'" :rightText="'申请状态:'+item.zt||'--'" />
		</uni-list>
		</uni-swipe-action-item>
		<uni-load-more :status="status" :contentText="contentText" />
		</uni-swipe-action>
		<view class="no-data" v-else style="text-align: center;">
			<image src="../../static/icons/nodata.png" style="width: 150rpx;" mode="widthFix"></image>
			<text>暂无数据</text>
		</view>
        
		<!-- 后送弹窗 -->
		<uni-popup ref="popup" background-color="#fff"  >
			<view class="popup-content" :class="{ 'popup-height': type === 'left' || type === 'right' }">
					<view class="example">
						<uni-forms ref="baseForm" :modelValue="baseFormData" label-width="100px">
							<uni-forms-item label="类型" class="wounded">
								<uni-data-checkbox style="margin-top: 10rpx;" v-model="baseFormData.lx" :localdata="lx" />
							</uni-forms-item>
							<uni-forms-item label="批次号" class="wounded">
								<uni-easyinput disabled="" v-model="baseFormData.pch"/>
							</uni-forms-item>
							<uni-forms-item label="方式" class="wounded">
								<uni-data-checkbox style="margin-top: 10rpx;" v-model="baseFormData.fs" :localdata="fs" />
							</uni-forms-item>
							<uni-forms-item label="送往" class="wounded">
								<uni-easyinput v-model="baseFormData.sw"/>
							</uni-forms-item>
							<uni-forms-item label="说明" class="wounded">
								<uni-easyinput type="textarea" v-model="baseFormData.bz"/>
							</uni-forms-item>
						</uni-forms>
					</view>
					<view class="fixedBottom">
						<button class="trueDecide" @click="trueDecide()">确定</button>
						<button class="cancel" @click="cancel()">取消</button>
					</view>
			</view>
		</uni-popup>
		<!-- 驳回弹窗 -->
		<uni-popup ref="inputDialog" type="dialog">
			<uni-popup-dialog ref="inputClose"  mode="input" title="驳回原因"
				placeholder="请输入驳回原因" @confirm="dialogInputConfirm"></uni-popup-dialog>
		</uni-popup>
	</view>
</template>
<script>
	import { evacuationManage,dictionary,lotNumber, evacuationConfirm, overrule } from '../../api/huanzhe.js'
	import { useRouter,toast } from '../../utils/utils.js'
	export default {
		data() {
			return {
				id:null,
				fs:[],
				lx:[],
				bh:[],
				baseFormData:{},
				options: [
					{
						text: '后送',
						value: 1,
						style: {
							backgroundColor: '#005500',
							height: '80px'
						}
					}, {
						text: '驳回',
						value: 2,
						style: {
							backgroundColor: '#ff0000'
						}
					}
				],
				recordingData:[],
				status: 'more',
				contentText: {
					contentdown: '上拉加载更多',
					contentrefresh: '加载中',
					contentnomore: '我也是有底线的~'
				},
				InquireData:{
					pageNum:1,
					pageSize: 20
				},
			}
		},
		onReachBottom(e){
			this.status = 'loading'
			this.InquireData.pageNum++;
			this.evacuationManages()
		},
		onLoad(){
			this.typeInjure()
			this.manner()
			this.evacuationManages()
		},
		methods: {
			cancel(){
				this.$refs.popup.close()
			},
			trueDecide(){
				var query={
					bz:this.baseFormData.bz,
					fs:this.baseFormData.fs,
					lx:this.baseFormData.lx,
					pch:this.baseFormData.pch,
					sw:this.baseFormData.sw,
					cqhsId:[this.id]
				}
				evacuationConfirm(query).then(res=>{
					toast(res.msg)
					if(res.cede===200){
						this.$refs.popup.close()
						this.baseFormData={}
					}else{
						this.$refs.popup.close()
					}
					this.evacuationManages()
				})
			},
			// 批次号查询
			lotNumbers(){
				lotNumber().then(res=>{
					this.baseFormData.pch=(parseInt(res.data)+1);
				})
			},
			// 方式查询
			manner(){
				dictionary('weiqin_housong_fangshi').then(res=>{
					res.data.forEach((item,index)=>{
						var fs={
							value:item.dictValue,
							text:item.dictLabel
						}
						this.fs.push(fs)
					})
				})
			},
			// 类型查询
			typeInjure(){
				dictionary('weiqin_housong_leixing').then(res=>{
					res.data.forEach((item,index)=>{
						var lx={
							value:item.dictValue,
							text:item.dictLabel
						}
						this.lx.push(lx)
					})
				})
			},
			// 驳回确认
			dialogInputConfirm(e){
				var bh={
					id:this.id,
					bhyy:e
				}
				this.bh.push(bh)
				overrule(this.bh).then(res=>{
					this.evacuationManages()
					toast(res.msg)
				})
			},
			onClickss(e, bh) {
				setTimeout(()=>{
					switch (e.content.value) {
						case 1:
						this.id=bh.id
						this.$refs.popup.open('bottom')
						this.lotNumbers()
						break
						case 2:
						this.id=bh.id
						this.$refs.inputDialog.open()
						break
					}
				},500)
			},
			evacuationManages(){
				evacuationManage(this.InquireData).then(res=>{
					if (!res.rows.length) {
						this.status = 'no-more'
					} else {
						this.status = 'more'
					}
					if (this.recordingData.length) {
						this.recordingData.push(...res.rows)
					} else {
						this.recordingData = res.rows
					}
				})
			},
			nursingDetail(item){
				useRouter('/pages/evacuation/detailEvacuation',{
					xm:item.xm,
					ssz:item.deptname,
					sj:item.sj,
					tw:item.tw,
					dj:item.dj,
					bz:item.bz,
					zt:item.zt,
					id:item.id
				},'navigateTo')
			}
		}
	}
</script>
<style lang="scss">
	::v-deep.uni-section .uni-section-header__decoration{
	    margin-right: 6px;
	    background-color: #23440d;
	}
		.popup-content {
			align-items: center;
			justify-content: center;
			padding: 15px;
			height: 900rpx;
			background-color: #fff;
		}
	
		.popup-height {
			width: 500px;
		}
		.no-data {
			position: absolute;
			top: 0rpx;
			left: 0;
			right: 0;
			bottom: 0;
			color: #333333;
			width: 100%;
			z-index: 1;
			display: flex;
			align-items: center;
			justify-content: center;
			flex-direction: column;
		}
		
	.fixedBottom{
			height: 200rpx;
			background-color: #FFF;
			position: fixed;
			bottom: 0rpx;
			left: 0;
			right: 0;
			display: flex;
			align-items: center;
			justify-content: space-between;
			z-index: 50;
			button{
				width: 300rpx;
				height: 88rpx;
				color: white;
				background-color: #23440d;
				border-radius: 20px;
				line-height: 88rpx;
				text-align: center;
			}
		}
</style>